import math

calculation_history = []

def calculate(expression: str) -> float:
    try:
        # 处理科学计算符号
        expr = expression.replace('^', '**').replace('√', 'math.sqrt')
        expr = expr.replace('π', str(math.pi)).replace('e', str(math.e))
        
        # 处理三角函数（假设角度制）
        if 'sin(' in expr:
            expr = expr.replace('sin', '_sin')
        if 'cos(' in expr:
            expr = expr.replace('cos', '_cos')
        if 'tan(' in expr:
            expr = expr.replace('tan', '_tan')

        # 确保表达式中括号能被正确处理，当前eval函数已支持括号，无需额外处理
        result = eval(expr, {
            '_sin': lambda x: math.sin(math.radians(x)),
            '_cos': lambda x: math.cos(math.radians(x)),
            '_tan': lambda x: math.tan(math.radians(x)),
            'math': math,
            '__builtins__': None
        })
        
        add_to_history(f'{expression} = {result}')
        return result
    except Exception as e:
        add_to_history(f'{expression} → 错误: {str(e)}')
        raise

def add_to_history(record: str):
    calculation_history.append(record)
    if len(calculation_history) > 10:
        calculation_history.pop(0)

def get_history() -> list:
    return calculation_history.copy()